//
//  XLUserInfoView.m
//  XiangLove
//
//  Created by 宋振 on 2018/8/6.
//  Copyright © 2018年 BAOMIHUA.COM. All rights reserved.
//

#define kSpace                          10
#define kLeft                           15
#define kRight                          15

#import "XLUserInfoView.h"
#import "XLPersonCenterTool.h"

@interface XLUserInfoView()

//姓名
@property (nonatomic, strong) UILabel *  nameLbl;

//身份证
@property (nonatomic, strong) UILabel *  cardLbl;

//手机号
@property (nonatomic, strong) UILabel *  iphoneLbl;

//开户行
@property (nonatomic, strong) UILabel *  bankLbl;

@end

@implementation XLUserInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.backgroundColor = RGBA(0, 0, 0, 0.4);
        
        /**
         设置界面显示
         */
        [self setCustomeView];
    }
    
    return self;
}

#pragma mark    - - - 设置界面显示 - - -

- (void)setCustomeView
{
    //设置背景显示
    UIView *bgView = [[UIView alloc] init];
    
    bgView.layer.cornerRadius = kScale(5);
    bgView.layer.masksToBounds = YES;
    bgView.backgroundColor = [UIColor whiteColor];
    
    [self addSubview:bgView];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self);
        make.centerY.equalTo(self.mas_centerY);
        make.left.equalTo(self.mas_left).offset(kScale(53));
        make.right.equalTo(self.mas_right).offset(-kScale(52));
        make.height.mas_equalTo(260);
//        make.size.mas_equalTo(CGSizeMake(270, 232));
    }];
    
    //标题显示
    UILabel *titileLbl = [[UILabel alloc] init];
    titileLbl.textAlignment = NSTextAlignmentCenter;
    titileLbl.attributedText = [[NSMutableAttributedString alloc] initWithString:@"信息确认" attributes:@{NSKernAttributeName:@1,NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:18],NSForegroundColorAttributeName:RGB(3, 3, 3)}];
    [self addSubview:titileLbl];
    
    [titileLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(bgView.mas_centerX);
        make.top.equalTo(bgView.mas_top).offset(20);
    }];
    
    //删除弹窗
    UIButton *deleteAlert = [UIButton buttonWithType:(UIButtonTypeCustom)];
    deleteAlert.frame = CGRectMake(0, 0, 12, 12);
    [deleteAlert setTitle:@"×" forState:(UIControlStateNormal)];
    [deleteAlert setTitleColor:RGB(153, 153, 153) forState:(UIControlStateNormal)];
    [deleteAlert addTarget:self action:@selector(deleteAlertAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:deleteAlert];
    
    [deleteAlert mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bgView).offset(-kScale(11));
        make.top.equalTo(bgView).offset(11);
        make.width.height.mas_equalTo(12);
    }];
    
    //设置名称
    [self addSubview:self.nameLbl];
    
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(57);
        make.left.equalTo(bgView).offset(kScale(kLeft));
        make.right.lessThanOrEqualTo(bgView).offset(-kScale(kRight));
    }];
    
    //设置身份证
    [self addSubview:self.cardLbl];
    
    [self.cardLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLbl.mas_bottom).offset(kSpace);
        make.left.equalTo(self.nameLbl.mas_left);
        make.right.lessThanOrEqualTo(bgView.mas_right).offset(-kScale(kRight));
        
    }];
    
    //手机号
    [self addSubview:self.iphoneLbl];
    
    [self.iphoneLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cardLbl.mas_bottom).offset(kSpace);
        make.left.right.equalTo(self.nameLbl);
    }];
    
    //开户银行
    [self addSubview:self.bankLbl];
    
    [self.bankLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iphoneLbl.mas_bottom).offset(kSpace);
        make.left.equalTo(bgView).offset(kScale(kLeft));
        make.right.equalTo(bgView).offset(-kScale(kRight));
    }];
    
    //确认按钮
    UIButton *commitBt = [UIButton buttonWithType:(UIButtonTypeCustom)];
    commitBt.frame = CGRectMake(0, 0, kScale(240), 40);
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:@"确定" attributes:@{NSForegroundColorAttributeName:RGB(255, 255, 255),NSFontAttributeName:[UIFont fontWithName:KFontNamePFMedium size:16]}];
    
    [commitBt setAttributedTitle:attribute forState:(UIControlStateNormal)];
    commitBt.layer.cornerRadius = 5;
    commitBt.layer.masksToBounds = YES;
    commitBt.backgroundColor = RGB(255, 187, 1);
    
    [commitBt addTarget:self action:@selector(commitAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:commitBt];
    
    [commitBt mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(kScale(kSpace));
        make.right.equalTo(bgView.mas_right).offset(-kScale(kSpace));
        make.bottom.equalTo(bgView.mas_bottom).offset(-kSpace);
        make.height.mas_equalTo(40);
    }];
    
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    //设置显示数据
    self.nameLbl.attributedText = [self setLabelWithTitle:self.name];
    
    self.cardLbl.attributedText = [self setLabelWithTitle:self.identifierCard];
    
    self.iphoneLbl.attributedText = [self setLabelWithTitle:self.iphoneNum];
    
    self.bankLbl.attributedText = [self setLabelWithTitle:self.bank];
}

#pragma mark    - - - Action - - -

//删除弹窗
- (void)deleteAlertAction:(UIButton *)sender
{
    if (self.delegate && [_delegate respondsToSelector:@selector(clickUserInfo:)]) {
        [self.delegate clickUserInfo:NO];
    }
}

//确定信息
- (void)commitAction:(UIButton *)sender
{
    if (self.delegate && [_delegate respondsToSelector:@selector(clickUserInfo:)]) {
        [self.delegate clickUserInfo:YES];
    }
}

#pragma mark    - - - 懒加载 - - -

- (UILabel *)nameLbl
{
    if (!_nameLbl) {
        self.nameLbl = [[UILabel alloc] init];
        self.nameLbl.textAlignment = NSTextAlignmentLeft;
        self.nameLbl.attributedText = [self setLabelWithTitle:@"姓名："];
    }
    
    return _nameLbl;
}

- (UILabel *)cardLbl
{
    if (!_cardLbl) {
        self.cardLbl = [[UILabel alloc] init];
        self.cardLbl.textAlignment = NSTextAlignmentLeft;
        self.cardLbl.attributedText = [self setLabelWithTitle:@"身份证："];
    }
    
    return _cardLbl;
}

- (UILabel *)iphoneLbl
{
    if (!_iphoneLbl) {
        self.iphoneLbl = [[UILabel alloc] init];
        self.iphoneLbl.textAlignment = NSTextAlignmentLeft;
        self.iphoneLbl.attributedText = [self setLabelWithTitle:@"手机号："];
    }
    
    return _iphoneLbl;
}

- (UILabel *)bankLbl
{
    if (!_bankLbl) {
        self.bankLbl = [[UILabel alloc] init];
        self.bankLbl.textAlignment = NSTextAlignmentLeft;
        self.bankLbl.numberOfLines = 2;
        self.bankLbl.attributedText = [self setLabelWithTitle:@"开户银行："];
    }
    
    return _bankLbl;
}

#pragma mark    - - - Help Tools - - -

- (NSMutableAttributedString *)setLabelWithTitle:(NSString *)title
{
    NSDictionary *dic = @{NSKernAttributeName:@1,
                          NSForegroundColorAttributeName:RGB(102, 102, 102),
                          NSFontAttributeName:[UIFont fontWithName:kFontNamePFRegular size:kScale(15)]
                          };
    
    NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:title attributes:dic];
    
    return attribute;
}

#pragma mark    - - - getter - - -

- (NSString *)name
{
    return [NSString stringWithFormat:@"姓名：%@",K_DEFULT(_name)];
}

- (NSString *)identifierCard
{
    return [NSString stringWithFormat:@"身份证：%@",K_DEFULT(_identifierCard)];
}

- (NSString *)iphoneNum
{
    return [NSString stringWithFormat:@"手机号：%@",K_DEFULT(_iphoneNum)];
}

- (NSString *)bank
{
    return [NSString stringWithFormat:@"开户银行：%@",K_DEFULT(_bank)];
}

@end
